import { notification, message } from 'antd';
import cloneDeep from 'lodash/cloneDeep';
import _map from 'lodash/map';
import _uniq from 'lodash/uniq';
import _pull from 'lodash/pull';
import { GetDateThree, FormatnumberZero } from '../../../../function';
import { getDQ, delDQ, addDQ } from '../../../../services/allposition_service';
import { delExchange } from '../../../../services/foreignExchange_service';

export default {
  namespace: 'dq',
  state: {
    aqdq: { code: 0, message: '', list: [], bondTypes: [] },
  },

  effects: {
    // stock
    *GetDQ({ payload, callback }, { call, put }) {
      const response = yield call(getDQ, payload);
      if (typeof response === 'undefined') {
        return;
      }
      if (typeof response !== 'undefined' && response.code === 1) {
        if (callback) callback(response);
      } else {
        notification.error({
          message: typeof response.message !== 'undefined' ? response.message : '请求错误',
        });
      }
    },
    *DelDQ({ payload, callback }, { call, put }) {
      const response = yield call(delDQ, payload);
      if (typeof response === 'undefined') {
        return;
      }
      if (typeof response !== 'undefined' && response.code === 1) {
        message.success(response.message);
        if (callback) callback(response);
      } else {
        notification.error({
          message: typeof response.message !== 'undefined' ? response.message : '请求错误',
        });
      }
    },
    *UpdateDQ({ payload, callback }, { call, put }) {
      const response = yield call(updateDQ, payload);
      if (typeof response === 'undefined') {
        return;
      }
      if (typeof response !== 'undefined' && response.code === 1) {
        message.success(response.message);
        if (callback) callback(response);
      } else {
        notification.error({
          message: typeof response.message !== 'undefined' ? response.message : '请求错误',
        });
      }
    },

    *AddDQ({ payload, callback }, { call, put }) {
      const response = yield call(addDQ, payload);
      if (typeof response === 'undefined') {
        return;
      }
      if (typeof response !== 'undefined' && response.code === 1) {
        message.success(response.message);
        if (callback) callback(response);
      } else {
        notification.error({
          message: typeof response.message !== 'undefined' ? response.message : '请求错误',
        });
      }
    },
  },

  reducers: {
    saveBonds(state, action) {
      return {
        ...state,
        bonds: action.payload,
      };
    },
  },
};
